#include <string.h>
#include <jni.h>

int pow(int i);

jstring Java_com_huaqin_hellojni_MainActivity_stringFromJNI(JNIEnv* env,
		jobject thiz) {
	return (*env)->NewStringUTF(env, "Hello from JNI !");
}

jlong Java_com_huaqin_hellojni_MainActivity_Add(JNIEnv *env, jobject this, jlong x, jlong y) {
	int n, i, temp, sum = 0;
	int k = 0;
//	scanf("%d", &n);
	temp = 2;
	for (i = 0; temp != 0; i++)
		temp = temp / 10;
	k = n / pow(i - 1);
	if (k == 1)
		sum = sum + n % pow(i - 1) + 1;
	if (k > 1)
		sum = sum + pow(i - 2);
	for (i = i - 2; i != 2; i--) {
		k = (n / pow(i - 1)) % 10;
		if (k == 0)
			sum = sum + (n / pow(i)) * 10;
		if (k == 1)
			sum = sum + (n / pow(i)) * 10 + (n / pow(i - 2) % 10) + 1;
		if (k > 1) {
			sum = sum + ((n / pow(i)) + 1) * 10;
			if (n / pow(i - 2) % 10 >= 1)
				sum = sum + 1;
		}
	}

	if (n / pow(i - 1) % 10 >= 1)
		sum = sum + n / pow(i - 1) + 1;
	else
		sum = sum + n / pow(i - 1);
	printf("%d", sum);

	return x + y;
}

int pow(int i) {
	int tens = 1;
	if (i == 0)
		return tens;
	else
		tens = 10 * pow(i - 1);
	return tens;
}
